package com.jimet.process;

import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;

public abstract class FormProcessBase {
	protected String strResult;
	protected String strObjectName;
	
	public FormProcessBase() {
		this.strResult = "";
		this.strObjectName = "[N/A]";
	}

	public String getStrResult() {
		return strResult;
	}
	public void setStrResult(String strResult) {
		this.strResult = strResult;
	}

	
	public String getStrObjectName() {
		return strObjectName;
	}

	public void setStrObjectName(String strObjectName) {
		this.strObjectName = strObjectName;
	}

	public void doProcess( HttpServletRequest request ){
		boolean fatalError = false;
		
		try{
			this.process(request);
		}
		catch(Exception ex)
		{ 
			ex.printStackTrace(); 
			fatalError = true;
			ex.printStackTrace();
			return;
		}
		finally{
			if (fatalError){
				try{
					this.strResult +=  "resultErrMsg="+URLEncoder.encode( this.getStrObjectName() + " kaydedilemedi. {HATA 1001}","UTF-8")+"&";
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	public void doProcess( HttpServletRequest request , Object paramObj ){
		boolean fatalError = false;
		
		try{
			this.process(request,paramObj);
		}
		catch(Exception ex)
		{ 
			ex.printStackTrace(); 
			fatalError = true;
			ex.printStackTrace();
			return;
		}
		finally{
			if (fatalError){
				try{
					this.strResult +=  "resultErrMsg="+URLEncoder.encode( this.getStrObjectName() + " kaydedilemedi. {HATA 1001}","UTF-8")+"&";
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}	
	
	protected abstract void process( HttpServletRequest request ) throws Exception;
	protected abstract void process( HttpServletRequest request , Object paramObj) throws Exception;
	
}
